package com.atguigu.cloud.controller;

import com.atguigu.cloud.entities.dto.PayDTO;
import com.atguigu.cloud.entities.resp.ResultData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @author ChengY
 * @since 2024/5/16 10:32
 */
@Tag(name = "支付微服务")
@RestController
public class OrderController {

    public static final String PAYMENT_URL = "http://localhost:8001";

    @Resource
    private RestTemplate restTemplate;

    @Operation(summary = "新增订单", description = "新增订单")
    @PostMapping("/consumer/pay/add")
    public ResultData<String> addOrder(@RequestBody PayDTO pay) {
        ResultData resultData = restTemplate.postForObject(PAYMENT_URL + "/pay/add", pay, ResultData.class);
        return resultData;
    }

    @Operation(summary = "获取订单", description = "获取订单")
    @GetMapping("/consumer/pay/get/{id}")
    public ResultData<Object> getPayInfo(@PathVariable("id") Integer id) {
        return restTemplate.getForObject(PAYMENT_URL + "/pay/get/" + id, ResultData.class, id);
    }

}
